package com.sky.controller.admin;


import com.sky.constant.StatusConstant;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜品管理
 */
@Api(tags = "菜品相关接口")
@RestController
@RequestMapping("/admin/dish")
@Slf4j
public class DishController {

    @Autowired
    DishService dishService;
    @PostMapping
    @ApiOperation("新增菜品")
    public Result<String> dish(@RequestBody DishDTO dishDTO){
        log.info("新增菜品，接收到DishDto，{}",dishDTO);
        dishService.saveWithFlavor(dishDTO);
        return Result.success();
    }

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO)
    {
        log.info("菜品分页查询，{}",dishPageQueryDTO);
        return dishService.page(dishPageQueryDTO);
    }

    /**
     * 删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result<String> delete(@RequestParam List<Long> ids){
        log.info("菜品批量删除：{}",ids);
        return dishService.delete(ids);
    }

    @PostMapping("/status/{status}")
    @ApiOperation("修改菜品状态")
    public Result<String> changeStatus(@PathVariable int status,Long id)
    {
        return dishService.changeStatus(status,id);
    }

    @GetMapping("/{id}")
    @ApiOperation(("根据id查询菜品"))
    public Result<DishVO> getById(@PathVariable Long id){
        return dishService.getById(id);
    }

    @PutMapping
    @ApiOperation("修改菜品信息")
    public Result<String> updateDish(@RequestBody DishDTO dishDTO)
    {
        return dishService.updateDishWithFlavors(dishDTO);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result<List<Dish>> getByCategoryId(Long categoryId){
        return dishService.getByCategory(categoryId);
    }
}
